<template>
  <el-dialog
    @close="handleClose(false)"
    v-dialogDrag
    :title="'选择合炉规则'"
    :visible="showDialog"
    width="40%"
  >
    <el-form
      :model="form"
      ref="form"
      :rules="rules"
      label-width="80px"
      :inline="false"
      size="small"
    >
      <el-form-item label="合炉规则" prop="ruleId">
        <el-select
          class="w100"
          v-model="form.ruleId"
          placeholder="请选择合炉规则"
          size="small"
        >
          <el-option
            v-for="item in rulesOptions"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="handleClose(false)">取 消</el-button>
      <el-button
        size="mini"
        type="primary"
        :loading="btnLoading"
        @click="submitForm()"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false,
    },
    rulesOptions: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      btnLoading: false,
      rules: {
        ruleId: [
          { required: true, message: "请选择合炉规则", trigger: "change" },
        ],
      },
      form: {
        ruleId: "",
      },
    };
  },
  methods: {
    handleClose() {
      this.$emit("update:showDialog", false);
    },
    submitForm() {
      this.$refs["form"].validate(async (valid) => {
        if (valid) {
          this.btnLoading = true;
          this.$emit("submitForm", this.form.ruleId);
        }
      });
    },
  },
};
</script>

<style>
</style>